from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-04 14:02:24.691002
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 04, Sep, 2022
Time: 14:02:30
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3144
Nobs: 769.000 HQIC: -50.6488
Log likelihood: 9824.43 FPE: 8.17814e-23
AIC: -50.8580 Det(Omega_mle): 7.28039e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299219 0.054511 5.489 0.000
L1.Burgenland 0.106684 0.036296 2.939 0.003
L1.Kärnten -0.106924 0.019282 -5.545 0.000
L1.Niederösterreich 0.204816 0.075884 2.699 0.007
L1.Oberösterreich 0.114676 0.073487 1.560 0.119
L1.Salzburg 0.252978 0.038839 6.513 0.000
L1.Steiermark 0.036111 0.050628 0.713 0.476
L1.Tirol 0.107052 0.041016 2.610 0.009
L1.Vorarlberg -0.060720 0.035265 -1.722 0.085
L1.Wien 0.050871 0.065282 0.779 0.436
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060201 0.113224 0.532 0.595
L1.Burgenland -0.034816 0.075390 -0.462 0.644
L1.Kärnten 0.047302 0.040051 1.181 0.238
L1.Niederösterreich -0.176427 0.157617 -1.119 0.263
L1.Oberösterreich 0.395214 0.152640 2.589 0.010
L1.Salzburg 0.290407 0.080673 3.600 0.000
L1.Steiermark 0.105745 0.105159 1.006 0.315
L1.Tirol 0.314538 0.085195 3.692 0.000
L1.Vorarlberg 0.027011 0.073249 0.369 0.712
L1.Wien -0.021926 0.135598 -0.162 0.872
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191810 0.028008 6.848 0.000
L1.Burgenland 0.089585 0.018649 4.804 0.000
L1.Kärnten -0.008554 0.009907 -0.863 0.388
L1.Niederösterreich 0.261177 0.038990 6.699 0.000
L1.Oberösterreich 0.134057 0.037759 3.550 0.000
L1.Salzburg 0.045826 0.019956 2.296 0.022
L1.Steiermark 0.018124 0.026013 0.697 0.486
L1.Tirol 0.093283 0.021075 4.426 0.000
L1.Vorarlberg 0.058224 0.018120 3.213 0.001
L1.Wien 0.117592 0.033543 3.506 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107939 0.028484 3.789 0.000
L1.Burgenland 0.047628 0.018966 2.511 0.012
L1.Kärnten -0.014868 0.010076 -1.476 0.140
L1.Niederösterreich 0.191035 0.039652 4.818 0.000
L1.Oberösterreich 0.290128 0.038400 7.555 0.000
L1.Salzburg 0.111369 0.020295 5.487 0.000
L1.Steiermark 0.103060 0.026455 3.896 0.000
L1.Tirol 0.110632 0.021433 5.162 0.000
L1.Vorarlberg 0.069804 0.018427 3.788 0.000
L1.Wien -0.017475 0.034113 -0.512 0.608
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131299 0.051723 2.538 0.011
L1.Burgenland -0.051294 0.034440 -1.489 0.136
L1.Kärnten -0.040326 0.018296 -2.204 0.028
L1.Niederösterreich 0.170452 0.072003 2.367 0.018
L1.Oberösterreich 0.139787 0.069729 2.005 0.045
L1.Salzburg 0.287914 0.036853 7.812 0.000
L1.Steiermark 0.033254 0.048039 0.692 0.489
L1.Tirol 0.161773 0.038919 4.157 0.000
L1.Vorarlberg 0.100498 0.033462 3.003 0.003
L1.Wien 0.068582 0.061944 1.107 0.268
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056086 0.041172 1.362 0.173
L1.Burgenland 0.040322 0.027414 1.471 0.141
L1.Kärnten 0.050494 0.014564 3.467 0.001
L1.Niederösterreich 0.220550 0.057315 3.848 0.000
L1.Oberösterreich 0.282553 0.055505 5.091 0.000
L1.Salzburg 0.045391 0.029335 1.547 0.122
L1.Steiermark -0.000580 0.038239 -0.015 0.988
L1.Tirol 0.147955 0.030980 4.776 0.000
L1.Vorarlberg 0.072920 0.026636 2.738 0.006
L1.Wien 0.085106 0.049308 1.726 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179532 0.049300 3.642 0.000
L1.Burgenland -0.005730 0.032826 -0.175 0.861
L1.Kärnten -0.061392 0.017439 -3.520 0.000
L1.Niederösterreich -0.084078 0.068629 -1.225 0.221
L1.Oberösterreich 0.196028 0.066462 2.949 0.003
L1.Salzburg 0.056368 0.035126 1.605 0.109
L1.Steiermark 0.231211 0.045788 5.050 0.000
L1.Tirol 0.494011 0.037095 13.317 0.000
L1.Vorarlberg 0.048008 0.031894 1.505 0.132
L1.Wien -0.051825 0.059041 -0.878 0.380
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166225 0.056614 2.936 0.003
L1.Burgenland -0.010319 0.037696 -0.274 0.784
L1.Kärnten 0.067099 0.020026 3.351 0.001
L1.Niederösterreich 0.206070 0.078812 2.615 0.009
L1.Oberösterreich -0.070911 0.076323 -0.929 0.353
L1.Salzburg 0.211544 0.040338 5.244 0.000
L1.Steiermark 0.115645 0.052581 2.199 0.028
L1.Tirol 0.072011 0.042599 1.690 0.091
L1.Vorarlberg 0.121557 0.036626 3.319 0.001
L1.Wien 0.122668 0.067801 1.809 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357318 0.032732 10.917 0.000
L1.Burgenland 0.005771 0.021794 0.265 0.791
L1.Kärnten -0.023353 0.011578 -2.017 0.044
L1.Niederösterreich 0.213957 0.045565 4.696 0.000
L1.Oberösterreich 0.188217 0.044126 4.265 0.000
L1.Salzburg 0.045885 0.023322 1.967 0.049
L1.Steiermark -0.015453 0.030400 -0.508 0.611
L1.Tirol 0.106621 0.024629 4.329 0.000
L1.Vorarlberg 0.073609 0.021175 3.476 0.001
L1.Wien 0.048782 0.039200 1.244 0.213
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040075 0.148070 0.192343 0.157297 0.124466 0.112992 0.065961 0.222342
Kärnten 0.040075 1.000000 -0.003961 0.132663 0.041492 0.095764 0.430867 -0.052313 0.100481
Niederösterreich 0.148070 -0.003961 1.000000 0.337626 0.151644 0.297942 0.107097 0.183275 0.322700
Oberösterreich 0.192343 0.132663 0.337626 1.000000 0.228720 0.330629 0.172602 0.167915 0.264880
Salzburg 0.157297 0.041492 0.151644 0.228720 1.000000 0.147769 0.122441 0.147321 0.133522
Steiermark 0.124466 0.095764 0.297942 0.330629 0.147769 1.000000 0.151340 0.138587 0.079414
Tirol 0.112992 0.430867 0.107097 0.172602 0.122441 0.151340 1.000000 0.115167 0.153050
Vorarlberg 0.065961 -0.052313 0.183275 0.167915 0.147321 0.138587 0.115167 1.000000 0.006859
Wien 0.222342 0.100481 0.322700 0.264880 0.133522 0.079414 0.153050 0.006859 1.000000